import Axios from "axios";

export function getHeaders(array) {
    if (array == null) {
        return;
    }
    const result = array.reduce((obj, item) => {
        obj[item.paramsName] = item.paramsValue;
        return obj;
    }, {});
    console.log(result);
    return result;
}

const axiosInstance = Axios.create();

axiosInstance.interceptors.response.use(
    response => {
        return response.data;
    },
    error => {
        return Promise.reject(error);
    }
);

export function testRequest(url, method, headers, params,data) {
    return axiosInstance({
        url: url,
        method: method,
        headers: getHeaders(headers),
        params:getHeaders(params),
        data: data
    });
}
